﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Collections.ObjectModel;
using System.ComponentModel;

namespace ChatApplication_Wpf
{
    /// <summary>
    /// Interaction logic for HomePage.xaml
    /// </summary>
    public partial class HomePage : UserControl
    {
        public ObservableCollection<ChatProperties> ListValue { get; set; }
        App app = Application.Current as App;
        public HomePage()
        {   
            InitializeComponent();
            
            ListValue = new ObservableCollection<ChatProperties>();
            ChatServerEntities1 entitires = new ChatServerEntities1();
            var result = (from d in entitires.User_Friend_Mapping
                          where d.User_Name == app.Username
                          select d).ToList();

            if (result != null)
            {
                foreach (var item in result)
                {      
                    var status = (from d in entitires.User_Details
                                  where d.User_Id == item.Friend_Name
                                  select d.Login_Status).SingleOrDefault();

                    SolidColorBrush colour = null;
                    switch (status)
                    {
                        case "Online":
                            colour = Brushes.Green;
                            break;
                        case "Offline":
                            colour = Brushes.Red;
                            break;
                        default:
                            colour = Brushes.Orange;
                            break;
                    }
                    ListValue.Add(new ChatProperties() { Name = item.Friend_Name, Status = status, StatusColour = colour });
                }

                ContentList.ItemsSource = ListValue;
            }
        }


        
    }    
}
